package util;

import com.google.gson.Gson;
import po.Course;
import po.CourseStudent;
import service.CourseService;
import service.CourseStudentService;
import service.StudentService;
import service.serviceImpl.CourseServiceImpl;
import service.serviceImpl.CourseStudentServiceImpl;
import service.serviceImpl.StudentServiceImpl;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 润
 */
public class ServletRepeat {


    public static String getJson(boolean result1) {
        Map<String, Object> map = new HashMap<>();
        map.put("result1", result1);
        Gson gson = new Gson();
        String json = gson.toJson(map);
        return json;
    }

    public static String getJson2(boolean result2) {
        Map<String, Object> map = new HashMap<>();
        map.put("result2", result2);
        Gson gson = new Gson();
        String json = gson.toJson(map);
        return json;

    }

    public static String getJson3(boolean result3) {
        Map<String, Object> map = new HashMap<>();
        map.put("result3", result3);
        Gson gson = new Gson();
        String json = gson.toJson(map);
        return json;
    }

    public static String getJson4(boolean result4) {
        Map<String, Object> map = new HashMap<>();
        map.put("result4", result4);
        Gson gson = new Gson();
        String json = gson.toJson(map);
        return json;
    }


    public static String getJson5(boolean result5) {
        Map<String, Object> map = new HashMap<>();
        map.put("result5", result5);
        Gson gson = new Gson();
        String json = gson.toJson(map);
        return json;
    }

    public static CourseStudent getCs(Integer i, Integer s) {
        CourseStudent courseStudent = new CourseStudent();
        courseStudent.setCid(i);
        courseStudent.setSid(s);
        return courseStudent;
    }

    public static void updateNumber(Integer cid) {
        CourseStudentService service = new CourseStudentServiceImpl();
        CourseService service1 = new CourseServiceImpl();
        Integer number = service.haveChooseNumber(cid);
        Course course = service1.queryOne(cid);
        course.setNumber(number);
        service1.update(course);
    }

    public static String coding(String number) {
        String time = "0";
        for (int w = 0; w < number.length(); w++) {
            if ("一".equals(String.valueOf(number.charAt(w)))){
                time+= "1";
            }
            if ("二".equals(String.valueOf(number.charAt(w)))){
                time += "2";
            }
            if ("三".equals(String.valueOf(number.charAt(w)))){
                time += "3";
            }
            if ("四".equals(String.valueOf(number.charAt(w)))){
                time += "4";
            }
            if ("五".equals(String.valueOf(number.charAt(w)))){
                time += "5";
            }
            if ("六".equals(String.valueOf(number.charAt(w)))){
                time += "6";
            }
            if ("日".equals(String.valueOf(number.charAt(w)))){
                time += "7";
            }
        }
        for (int r = 0; r < number.length(); r++) {
            if ("1".equals(String.valueOf(number.charAt(r)))){
                time += "1";
            }
            if ("2".equals(String.valueOf(number.charAt(r)))){
                time += "2";
            }
            if ("3".equals(String.valueOf(number.charAt(r)))){
                time += "3";
            }
            if ("4".equals(String.valueOf(number.charAt(r)))){
                time += "4";
            }
            if ("5".equals(String.valueOf(number.charAt(r)))){
                time += "5";
            }
            if ("6".equals(String.valueOf(number.charAt(r)))){
                time += "6";
            }
            if ("7".equals(String.valueOf(number.charAt(r)))){
                time += "7";
            }
            if ("8".equals(String.valueOf(number.charAt(r)))){
                time += "8";
            }
            if ("9".equals(String.valueOf(number.charAt(r)))){
                time += "9";
            }
        }

     return time;
 }


}
